package com.squapsource.project_euler;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.io.FileUtils;

public class Problem22 {

	/**
	 * @param args
	 * @throws URISyntaxException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws URISyntaxException, IOException {
		File namesFile = new File(Problem22.class.getResource("/Problem22.txt")
				.toURI());

		String nameString = FileUtils.readFileToString(namesFile).replace("\"", "");
		List<String> names = Arrays.asList(nameString.split(","));
		Collections.sort(names);
		long sum =0;
		for (String name : names)
		{
			sum += (names.indexOf(name)+1)*getValueOfName(name);
		}
		
		System.out.println(sum);

	}

	private static int getValueOfName(String name) {
		int sum = 0;
		for (Character c : name.toCharArray())
		{
			sum += (c.charValue()%'A')+1;
		}
		return sum;
	}

}
